package com.yaozheng.vocationaltraining.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.bean.MyExamItemBean;
import com.yaozheng.vocationaltraining.bean.PKGameCategoryBean;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;
import com.yaozheng.vocationaltraining.view.ExamProgressStatusView_;

import java.util.List;

/**
 * Created by moon on 2017/11/20.
 */

public class MyExamItemAdapter extends BaseAdapter {
    private LayoutInflater mInflater;//
    private Activity mContext;
    private BitmapLoader userBitmapLoader;

    private List<MyExamItemBean> data = null;

    private int selectedPosition = -1;

    public MyExamItemAdapter(Activity context,
                                 List<MyExamItemBean> data) {
        this.mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.data = data;
        userBitmapLoader = new BitmapLoader(Glide.with(context), R.drawable.user_img);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(
                    R.layout.my_exam_list_item, null);
            holder = new ViewHolder();

            holder.examProgressStatusView = (ExamProgressStatusView_) convertView
                    .findViewById(R.id.examProgressStatusView);
            holder.paperTimeText = (TextView) convertView
                    .findViewById(R.id.paperTimeText);

            holder.paperTitleText = (TextView) convertView
                    .findViewById(R.id.paperTitleText);
            holder.paperStartTimeText = (TextView) convertView
                    .findViewById(R.id.paperStartTimeText);


            convertView.setTag(holder);//
        } else {
            holder = (ViewHolder) convertView.getTag();//
        }

        holder.paperTimeText.setText(data.get(position).getStartTime());
        holder.paperTitleText.setText(data.get(position).getSubject());
        holder.paperStartTimeText.setText(data.get(position).getStartTime());

        holder.examProgressStatusView.setStatus(data.get(position).getScore());
        return convertView;
    }

    public void setData(List<MyExamItemBean> data) {
        this.data = data;
    }

    public void setselectedPosition(int selectedPosition) {
        notifyDataSetChanged();;
    }

    class ViewHolder {
        ExamProgressStatusView_ examProgressStatusView;
        TextView paperTimeText;
        TextView paperTitleText;
        TextView paperStartTimeText;
    }
}
